import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;
@WebServlet("/requestServlet03")
public class RequestServlet03  extends HttpServlet{
    @Override
    protected  void  service(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
        req.setCharacterEncoding("UTF-8");
        Enumeration<String> parameterNames = req.getParameterNames();
        System.out.println("请求中所有参数的名称：");
        while (parameterNames.hasMoreElements()){
            String paramName = parameterNames.nextElement();
            System.out.println(paramName);
        }
        String username = req.getParameter("username");
        System.out.println("请求中参数username的值:" + username);

        String[] sports = req.getParameterValues("sports");
        System.out.println("请求中参数sports的值");
        for (String sport :sports){
            System.out.println(sport + " ");
        }
        Map<String,String[]> parameterMap = req.getParameterMap();
        System.out.println("所有请求参数的键值对集合:");
        for (Map.Entry<String,String[]> entry : parameterMap.entrySet()){
            String paramName = entry.getKey();
            String[] paramValues = entry.getValue();
            System.out.println("Name:" + paramName + ",Values:" + Arrays.toString(paramValues));
        }
    }
}
